

struct VPixelContext
{

};



struct FRAGMENT_IN {
	float4 texcoord_0 : TEXCOORD0;
	float3 texcoord_1 : TEXCOORD1;
	#ifdef USE_DEFERRED || USE_OCCLUSION
		half3 texcoord_2 : TEXCOORD2;
		half3 texcoord_3 : TEXCOORD3;
		half3 texcoord_4 : TEXCOORD4;
	#endif
	#ifdef USE_PARALLAX && PARALLAX
		half3 texcoord_5 : TEXCOORD5;
		half2 texcoord_6 : TEXCOORD6;
	#endif
	#ifdef USE_ALPHA_FADE && ALPHA_FADE
		float4 texcoord_7 : TEXCOORD7;
	#endif
};

half4 detail_transform;
half4 emission_color;
half emission_scale;
half glow_scale;
half4 diffuse_color;
half specular_power;

/*
 */
FRAGMENT_DEFERRED_OUT main(FRAGMENT_IN IN) 
{
	
	FRAGMENT_DEFERRED_OUT OUT;
	
	#ifdef USE_ALPHA_FADE && ALPHA_FADE
		tex2DAlphaFadeDiscard(s_texture_9,IN.texcoord_7,IN.texcoord_7.z);
	#endif
	
	float distance = length(IN.texcoord_1);
	
	#ifdef VOLUMETRIC
		OUT.color_0 = setDeferredDepth(distance,1.0f);
	#else
		OUT.color_0 = setDeferredDepth(distance,0.0f);
	#endif
	
	float2 texcoord = IN.texcoord_0.xy;
	
	#ifdef USE_PARALLAX
		
		#ifdef PARALLAX
			
			half3 camera_direction = normalize(IN.texcoord_5);
			half2 parallax = camera_direction.xy * IN.texcoord_6 / abs(camera_direction.z);
			
			#ifdef QUALITY_HIGH
				
				half istep = 1.0f / 32.0f;
				half2 step = parallax * istep;
				
				half x,y,xh,yh;
				half threshold = 1.0f;
				[loop] for(float i = 0.0f; i <= 32.0f; i += 1.0f) {
					texcoord -= step;
					half h = tex2Dlod(s_texture_10,float4(texcoord,0.0f,0.0f)).x;
					threshold -= istep;
					if(h > threshold) {
						x = threshold;
						xh = h;
						i = 1024.0f;
					} else {
						yh = h;
					}
				}
				y = x + istep;
				
			#else
				
				half4 texcoord_0 = texcoord.xyxy - parallax.xyxy * half4(1.000f,1.000f,0.875f,0.875f);
				half4 texcoord_1 = texcoord.xyxy - parallax.xyxy * half4(0.750f,0.750f,0.625f,0.625f);
				half4 texcoord_2 = texcoord.xyxy - parallax.xyxy * half4(0.500f,0.500f,0.375f,0.375f);
				half4 texcoord_3 = texcoord.xyxy - parallax.xyxy * half4(0.250f,0.250f,0.125f,0.125f);
				
				half h0 = tex2D(s_texture_10,texcoord_0.xy).x;
				half h1 = tex2D(s_texture_10,texcoord_0.zw).x;
				half h2 = tex2D(s_texture_10,texcoord_1.xy).x;
				half h3 = tex2D(s_texture_10,texcoord_1.zw).x;
				half h4 = tex2D(s_texture_10,texcoord_2.xy).x;
				half h5 = tex2D(s_texture_10,texcoord_2.zw).x;
				half h6 = tex2D(s_texture_10,texcoord_3.xy).x;
				half h7 = tex2D(s_texture_10,texcoord_3.zw).x;
				
				float x,y,xh,yh;
				[flatten] if(h7 > 0.875f) { x = 0.875f; xh = h7; yh = h7; }
				else [flatten] if(h6 > 0.750f) { x = 0.750f; xh = h6; yh = h7; }
				else [flatten] if(h5 > 0.625f) { x = 0.625f; xh = h5; yh = h6; }
				else [flatten] if(h4 > 0.500f) { x = 0.500f; xh = h4; yh = h5; }
				else [flatten] if(h3 > 0.375f) { x = 0.375f; xh = h3; yh = h4; }
				else [flatten] if(h2 > 0.250f) { x = 0.250f; xh = h2; yh = h3; }
				else [flatten] if(h1 > 0.125f) { x = 0.125f; xh = h1; yh = h2; }
				else { x = 0.000f; xh = h0; yh = h1; }
				y = x + 0.125f;
				
			#endif
			
			half a = y - yh;
			half b = x - xh;
			
			half2 offset = -parallax * (1.0f - (x * a - y * b) / (a - b));
			
			texcoord = IN.texcoord_0.xy + offset;
			
			OUT.color_3 = setDeferredParallax(offset);
			
		#else
			
			OUT.color_3 = 0.0f;
			
		#endif
		
	#endif
	
	half4 diffuse = tex2DAlpha(s_texture_0,texcoord,1.0f);
	half3 normal = tex2D(s_texture_1,texcoord).xyz;
	
	#ifdef ALPHA_TEST && !MULTISAMPLE_0
		OUT.color_0.w = diffuse.w;
	#endif
	
	#ifdef OVERLAY_0 || OVERLAY_1 || MULTIPLY_0 || MULTIPLY_1
		
		#ifdef OVERLAY_0 || MULTIPLY_0
			float2 detail_texcoord = texcoord * detail_transform.xy + detail_transform.zw;
		#else
			float2 detail_texcoord = IN.texcoord_0.zw * detail_transform.xy + detail_transform.zw;
		#endif
		
		half4 detail_diffuse = tex2D(s_texture_3,detail_texcoord);
		half2 detail_normal = tex2D(s_texture_4,detail_texcoord).xy;
		
		#ifdef ALPHA_TEST
			half3 blend = s_material_detail * detail_diffuse.w;
		#else
			half3 blend = s_material_detail * (diffuse.w * detail_diffuse.w);
		#endif
		
		#ifdef OVERLAY_0 || OVERLAY_1
			diffuse.xyz = saturate(diffuse.xyz + (detail_diffuse.xyz * 2.0f - 1.0f) * blend.x);
		#else
			diffuse.xyz = diffuse.xyz * saturate(detail_diffuse.xyz + 1.0f - blend.x);
		#endif
		normal.xy = normal.xy + detail_normal * blend.y;
		
		normal.xy = normal.xy * 2.0f - 1.0f - blend.y;
		
	#else
		
		normal.xy = normal.xy * 2.0f - 1.0f;
		
	#endif
	
	diffuse *= diffuse_color;
	
	normal.z = sqrt(saturate(1.0f - dot(normal.xy,normal.xy)));
	
	#ifdef HAS_DEFERRED_COLOR
		#ifdef EMISSION
			half4 emission = tex2D(s_texture_11,texcoord);
			diffuse.xyz += emission.xyz * emission_color.xyz * emission_scale;
			OUT.color_1 = setDeferredColor(diffuse.xyz,emission.w * glow_scale);
		#else
			OUT.color_1 = setDeferredColor(diffuse.xyz,0.0f);
		#endif
	#endif
	
	#ifdef HAS_DEFERRED_NORMAL
		#ifdef USE_DEFERRED || USE_OCCLUSION
			half3 screen_normal;
			screen_normal.x = dot(IN.texcoord_2,normal);
			screen_normal.y = dot(IN.texcoord_3,normal);
			screen_normal.z = dot(IN.texcoord_4,normal);
			OUT.color_2 = setDeferredNormal(normalize(screen_normal),specular_power);
		#elif USE_PARALLAX
			OUT.color_2 = 0.0f;
		#endif
	#endif
	
	return OUT;
}



VPixelContext MeshInitPixelContext(VCommonV2F Input)
{

}